<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //1）new构建
      //a）创建一个空的对象
      var obj1 = new Object();
      //对空对象赋值  对象名.属性=值;对象名.方法名=function(){}
      obj1.name = "张三";
      obj1.age = 16;
      //方法
      obj1.fn = function () {
        console.log(11111);
      };
      console.log(obj1);
      console.log(obj1.name);
      obj1.fn();

      //b）创建对象的同时并对该对象初始化处理 属性名：值, 方法名：function(){},
      var obj2 = new Object({
        name: "李四",
        age: 13,
        fn2: function () {
          console.log("我是对象里面的方法2");
        },
      });
      console.log(obj2);

      //2）字面量定义
      //创建一个空对象
      var obj3 = {};
      obj3.name = "王麻子";
      obj3.age = 17;
      console.log(obj3);

      //创建对象的同时并对该对象进行初始化处理
      var obj4 = {
        name: "王五",
        age: 17,
        fn3: function () {
          console.log("我是对象里面的方法3");
        },
        fn4: function () {
          console.log("我是对象里面的方法4");
        },
      };
      console.log(obj4);
      obj4.fn4();
    </script>
  </body>
</html>
